import { extend, storage, deserialize } from './utils.js';
const login = {
    /**
     * 判断是否登录
     * @return promise
     */
    logged() {
        return new Promise((resolve, reject) => {
            try {
                let value = deserialize(uni.getStorageSync('userInfo'));
				console.log('打印-logged~~~~~~~~~~',value)
                if (value) {
                    if (value.code !== 0) {
                        resolve(value);
                    } else {
                        reject(value.code);
                    }
                } else {
                    storage.set('userInfo', {
                        code: 0,
                        data: ''
                    });
                    reject(0);
                }
            } catch (e) {
                console.log('CatchClause', e);
                console.log('CatchClause', e);
                console.log('获取本地userInfo错误');
            }
        });
    },
    /**
     * 登录
     * @params {object} data 用户信息
     * @params {number} mode 1默认接口登录，2手机注册登录，3微信登录
     */
    logon(data = {}, mode = 1, cb) {
        let result = extend(
            {},
            {
                mode: mode,
                code: 1,
                data: data
            }
        );
        storage.set('userInfo', result, (rs) => {
            if (cb) {
                cb();
            }
        });
    }
};
module.exports = {
    login: login
};
